<template>
  <div class="app-container">
    <el-descriptions title="消防设施————清洁频率">
      <el-descriptions-item label="一级养护建议清洁频率">1次/季度</el-descriptions-item>
      <el-descriptions-item label="二级养护建议清洁频率">1次/半年</el-descriptions-item>
      <el-descriptions-item label="三级养护建议清洁频率">1次/1年</el-descriptions-item>
    </el-descriptions>
    <hr>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="隧道名称" prop="field1">
        <el-select v-model="queryParams.field1" placeholder="请选择隧道名称" clearable @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in suidaoList"
            :key="item.id + ''"
            :label="item.field2"
            :value="item.field2 + ''"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备名称" prop="field2">
        <el-select
          v-model="queryParams.field2"
          placeholder="请选择设备名称"
          clearable
          @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in results"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      <br>
      <el-form-item label="养护等级">
        <el-input
          v-model="level"
          placeholder="隧道养护等级"
          clearable
          disabled=""
          size="small"
          @keyup.enter.native="handleQuery2"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery2">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery2">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['biz:xiaofangyanghu:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          v-if="false"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['biz:xiaofangyanghu:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          v-if="false"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['biz:xiaofangyanghu:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['biz:xiaofangyanghu:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="xiaofangyanghuList" @selection-change="handleSelectionChange">
      <el-table-column label="清洁维护单号" align="center" prop="id" />
      <el-table-column label="隧道名称" align="center" prop="field1" />
      <el-table-column label="设备名称" align="center" prop="field2" />
      <el-table-column label="养护机构" align="center" prop="field3" />
      <el-table-column
        label="养护日期"
        align="center"
        prop="field4"
        width="140"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.field4, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="养护措施" align="center" prop="field5" />
      <el-table-column label="养护人员" align="center" prop="field6" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['biz:xiaofangyanghu:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:xiaofangyanghu:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="隧道名称" prop="field1">
          <el-select v-model="form.field1" clearable placeholder="请选择隧道名称">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.id + ''"
              :label="dict.field2"
              :value="dict.field2 + ''"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设备名称" prop="field2">
          <el-select v-model="form.field2" clearable placeholder="请选择设备名称" clearable>
            <el-option
              v-for="item in results"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="养护机构" prop="field3">
          <el-input v-model="form.field3" clearable placeholder="请输入养护机构" />
        </el-form-item>
        <el-form-item label="养护日期" prop="field4">
          <el-date-picker
            clearable
            size="small"
            v-model="form.field4"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择养护日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="养护措施" prop="field5">
          <el-input v-model="form.field5" clearable placeholder="请输入养护措施" />
        </el-form-item>
        <el-form-item label="养护人员" prop="field6">
          <el-input v-model="form.field6" clearable placeholder="请输入养护人员" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>


<script>
  import { getlevelByTunnelName,listXiaofangyanghu, getXiaofangyanghu, delXiaofangyanghu, addXiaofangyanghu, updateXiaofangyanghu ,exportXiaofangyanghu} from "@/api/biz/xiaofangyanghu";
  import { listSuidao } from "@/api/biz/suidao";

  export default {
    name: "Xiaofangyanghu",
    data() {
      return {
        // 导出遮罩层
        exportLoading: false,
        results:[{
          value: '点型感烟感温探测器(40101)',
          label: '点型感烟感温探测器(40101)'
        }, {
          value: '双/三波长火焰探测器(40102)',
          label: '双/三波长火焰探测器(40102)'
        }, {
          value: '线型感温光纤火灾探测系统(40103)',
          label: '线型感温光纤火灾探测系统(40103)'
        }, {
          value: '光纤光楯感温火灾探测系统(40104)',
          label: '光纤光楯感温火灾探测系统(40104)'
        }, {
          value: '视频型火灾报警装置(40105)',
          label: '视频型火灾报警装置(40105)'
        }, {
          value: '手动报警按钮(40106)',
          label: '手动报警按钮(40106)'
        }, {
          value: '火灾报警控制器(40107)',
          label: '火灾报警控制器(40107)'
        }, {
          value: '液位检测器(40200)',
          label: '液位检测器(40200)'
        }, {
          value: '消火栓及灭火器(40300)',
          label: '消火栓及灭火器(40300)'
        }, {
          value: '阀门(40400)',
          label: '阀门(40400)'
        }, {
          value: '水喷雾灭火设施(40500)',
          label: '水喷雾灭火设施(40500)'
        }, {
          value: '水泵接合器(40600)',
          label: '水泵接合器(40600)'
        }, {
          value: '水泵(40700)',
          label: '水泵(40700)'
        }, {
          value: '电动机(40800)',
          label: '电动机(40800)'
        }, {
          value: '给水管(40900)',
          label: '给水管(40900)'
        }, {
          value: '气体灭火设施(41000)',
          label: '气体灭火设施(41000)'
        }, {
          value: '消防车、消防摩托车(41100)',
          label: '消防车、消防摩托车(41100)'
        }, {
          value: '消防水池(41200)',
          label: '消防水池(41200)'
        }, {
          value: '电光标志(41300)',
          label: '电光标志(41300)'
        }
        ],
        level: null,
        suidaoList: [],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 消防设施清洁维护表格数据
        xiaofangyanghuList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          field1: null,
          field2: null,
          field3: null,
          field4: null,
          field5: null,
          field6: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          field1: [
            { required: true, message: "隧道名称不能为空", trigger: "blur" },
          ],
          field2: [
            { required: true, message: "设备名称不能为空", trigger: "blur" },
          ],
          field3: [
            { required: true, message: "养护机构不能为空", trigger: "blur" },
          ],
          field4: [
            { required: true, message: "养护日期不能为空", trigger: "blur" },
          ],
          field5: [
            { required: true, message: "养护措施不能为空", trigger: "blur" },
          ],
          field6: [
            { required: true, message: "养护人员不能为空", trigger: "blur" },
          ],
        }
      };
    },
    created() {
      this.getList();
      listSuidao({}).then((response) => {
        this.suidaoList = response.rows;
      });
    },
    methods: {
      /** 查询消防设施清洁维护列表 */
      getList() {
        this.loading = true;
        listXiaofangyanghu(this.queryParams).then(response => {
          this.xiaofangyanghuList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          field1: null,
          field2: null,
          field3: null,
          field4: null,
          field5: null,
          field6: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      handleQuery2() {
        this.queryParams.pageNum = 1;
        getlevelByTunnelName(this.queryParams).then(response => {
          this.level = response.rows[0];
        });
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      resetQuery2() {
        this.level=null;
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加消防设施清洁维护";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getXiaofangyanghu(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改消防设施清洁维护";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateXiaofangyanghu(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addXiaofangyanghu(this.form).then(response => {
                this.$modal.msgSuccess("添加成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除消防设施清洁维护单号为"' + ids + '"的数据项？').then(function() {
          return delXiaofangyanghu(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const lists = this.getList();
        this.$modal
          .confirm("是否确认导出所有消防设施清洁维护数据项？")
          .then(() => {
            this.exportLoading = true;
            return exportXiaofangyanghu(lists);
          })
          .then((response) => {
            this.download(response.msg);
            this.exportLoading = false;
          })
          .catch(() => {});
      },
    }
  };
</script>
